#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2020-08-26 09:34:46
# @Author  : Zuo Zhongfei (zuozhongfei@126.com)
# @Link    : www
# @Version : $Id$

import os

# 打印问候语的简单函数

# 定义函数


def greet_user():
    """显示简单的问候语"""
    print('hello')


# 调用函数
greet_user()


# 带参数的函数
def greet_user(username):
    print("Hello," + username.title())


greet_user("jessi")


# 关键字实参：在传递参数时，指定参数的形参名和实参值，不必关心参数的顺序
def describe_pet(animal_type, pet_name):
    print("\nI hava a " + animal_type + ".")
    print("My " + animal_type + "'s name is " + pet_name + ".")


describe_pet(animal_type="狗", pet_name="旺财")
describe_pet(pet_name="旺财", animal_type="狗")

# 指定参数默认值
# 注意　使用默认值时，在形参列表中必须先列出没有默认值的形参，
# 再列出有默认值的形参。这让Python依然能够正确地解读位置实参。


def describe_pet1(animal_type, pet_name='erha'):
    print("\nI hava a " + animal_type + ".")
    print("My " + animal_type + "'s name is " + pet_name + ".")


describe_pet1(animal_type="狗")
describe_pet1("狗")

# 函数返回值


def get_formatted_name(first_name, last_name):
    full_name = first_name + ' ' + last_name
    return full_name


xiaoli = get_formatted_name("李", "明")
print(xiaoli)

# 结合是用函数和while循环
# def get_formatted_name(first_name, last_name):
#     full_name = first_name + " " + last_name
#     return full_name


# while True:
#     print("\nPlease tell me your name:")
#     print("(enter 'quit' at any time to quit)")
#     f_name = input("FirstName:")
#     if f_name == 'quit':
#         print("Bye Bye")
#         break
#     l_name = input("Last_name:")
#     if l_name == "quit":
#         print("Bye Bye")
#         break

#     formatted_name = get_formatted_name(f_name, l_name)
#     print('\nHello, ' + formatted_name + "!")

# 向函数中传递列表
def greet_users(names):
    for name in names:
        msg = "Hello, " + name.title() + "!"
        print(msg)


usernames = ['xiaoli', 'xiaowang', 'xiaozhang']
greet_users(usernames)
